{% import _self as self %}
{% set nextIcon = '<span class="e-pagination-button ' ~ 'app.icon.small.pagination.nextIcon' | trans ~ '"></span>' %}
{% set previousIcon = '<span class="e-pagination-button ' ~ 'app.icon.small.pagination.previousIcon' | trans ~ '"></span>' %}
{% set phaseFilterId = phaseFilterId|default(null) %}

{% set nextIcon = nextIcon|default('&gt;') %}
{% set previousIcon = previousIcon|default('&lt;') %}
<div class="row text-center">
    <div class="col-md-5 col-md-offset-3">
{% set route = route is defined ? route : app.request.attributes.get('_route')%}
{% if paginator.numpages != 1 %}
	<ul class="pagination">
	        {% if paginator.currentpage != 1 %}
	            <li> <a class="previous" href="{{ self.getPhat(route, reportId, filterId, appId, phaseFilterId, paginator.currentpage-1) }}">{{ previousIcon | raw }}</a>
	        {% else %}
	            <li class="disabled"><a href="#">{{ previousIcon | raw }}</a>
	        {% endif %}
	        
	        {% for i in 1..paginator.numpages%}
	            {% if paginator.range.0 > 2 and i == paginator.range.0 %}
	                  <li> <a href="#">...</a></li>
	            {% endif %}
	
	            {%  if(i==1 or i==paginator.numpages or i in paginator.range) %}
	                <li {{ i==paginator.currentpage? 'class="active"' : ''}}><a {{ i==paginator.currentpage? 'class="active"' : ''}} href="{{ self.getPhat(route, reportId, filterId, appId, phaseFilterId, i) }}"> {{i}}</a></li>
	            {% endif %}
	
	            {% if paginator.range[paginator.midrange -1] < paginator.numpages -1 and i == paginator.range[paginator.midrange-1] %}
	               <li> <a href="#">...</a></li>
	            {% endif %}
	        {% endfor %}
	        {% if paginator.numpages != paginator.currentpage %}
		        <li> <a class="next" href="{{ self.getPhat(route, reportId, filterId, appId, phaseFilterId, paginator.currentpage+1) }}">{{ nextIcon | raw }}</a>
	        {% else %}
	        	<li class="disabled"><a href="#">{{ nextIcon | raw }}</a>
	        {% endif %}
	</ul>
{% endif %}
    </div>
    <div class="col-md-4">
        <div class="pagination-number-text">
            {% if paginator.itemsCount == 0 %}
                No Records
            {% else %}
                {{ paginator.limit*(paginator.currentPage-1) + 1 }} - {{ min(paginator.limit*paginator.currentPage, paginator.itemsCount) }} out of {{ paginator.itemsCount }} records shown
            {% endif %}
        </div>
    </div>
</div>

{% macro getPhat(route, reportId, filterId, appId, phaseFilterId, offset) %}
{% set param = {'reportId': reportId, 'appId': appId, 'offset': offset} %}
{% if phaseFilterId is not null %}
    {% set param = param|merge({'phaseId': phaseFilterId}) %}
{% endif %}
{% if filterId is not null and filterId != 0 %}
    {% set param = param|merge({'filter': filterId}) %}
{% endif %}
{{ path(route, app.request.query.all|merge(param)) }}
{% endmacro %}